/*
 *  This class is used for displaying images notes in a specific manner
 */
package com.aoasaa;


import android.content.Context;

import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TableRow;
import android.widget.TextView;

public class ImageNotesListAdapter extends ArrayAdapter<String> 
{
	private LayoutInflater mInflater;
	private int mViewResourceId;
	int index; 
	int _checking_count=0;
	Context context;
	String[] _notesdates,_datecount,_titles,_time,_content,_imagenotesurl;
	public ImageNotesListAdapter(Context context, int ViewResourceId, String[] v_notesdates,String[] v_datecount,String[] v_titles,String[] v_time,String[] v_content,String[] v_imagenotesurl) 
	{
		super(context, ViewResourceId);
		// TODO Auto-generated constructor stub
		this.context=context;
		mViewResourceId=ViewResourceId;
		_notesdates=v_notesdates;
		_datecount=v_datecount;
		_titles=v_titles;
		_time=v_time;  
		_content=v_content; 
		_imagenotesurl=v_imagenotesurl;
	}
	@Override
	public int getCount() {
		return _notesdates.length;
	}

	@Override
	public String getItem(int position) {
		return _notesdates[position];
	}
  
	@Override
	public long getItemId(int position) {
		return 0;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) 
	{  
		
		mInflater= (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		convertView = mInflater.inflate(mViewResourceId, null);
		index=position;  
		try {
			// getting reference for linear layout from viewing saved imagenotes.xml
			LinearLayout l=(LinearLayout)convertView.findViewById(R.id.layout_imagenotes);
			// creating for-loop w.r.t number of dates available
			  // for(int i=0;i<_notesdates.length;i++)
			 //  { 
				   // for date and count
				   TableRow tr1=new TableRow(convertView.getContext());
				   TextView tv_date=new TextView(convertView.getContext());
				   TextView tv_count=new TextView(convertView.getContext());
				   tr1.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT));
				   tr1.addView(tv_date);
				   tr1.addView(tv_count);  
				   l.addView(tr1); 
				   tv_date.setText(_notesdates[position].toString());
				   tv_count.setText(_datecount[position].toString());
				   int check_val=_checking_count+Integer.parseInt(_datecount[position].toString());
				   for(int j=_checking_count; j<check_val; j++)
				   {  
					   // for time and title
					              
					   
					   TableRow tr2=new TableRow(convertView.getContext());
					   TextView tv_time=new TextView(convertView.getContext());
					   TextView tv_title=new TextView(convertView.getContext());
					  
					   tv_time.setText(_time[j].toString());
					   tv_title.setText(_titles[j].toString());
					   
					   tr2.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT));
					   tr2.addView(tv_time);
					   tr2.addView(tv_title);   
					   l.addView(tr2);  
					  
					   // for content and image
					    
					   TableRow tr3=new TableRow(convertView.getContext());
					   TextView tv_content=new TextView(convertView.getContext());
					  
					   tv_content.setText(_content[j].toString());
					   
					   // ImageView img_imageurl=new ImageView(context);
					   tr3.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT));
					   tr3.addView(tv_content);
					 //  tr3.addView(img_imageurl);  
					   l.addView(tr3);                                
					 
					   _checking_count=j;   
					   
					   
					    
				   }
				    
			   //}  
		    }
		catch (Exception e) 
		{
			e.printStackTrace();
		} 
		return convertView;
	}
	
}
